package com.dgut.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public class IUser implements UserDetails {

//    private long id;
//    private String username;
//    private String password;
//    private IRole iRole;
//    private Date lastPasswordResetDate;


    private String user_uuid;       //用户ID
    private String username;        //用户名
    private String password;        //密码
    private String email;           //邮箱
    private String mobile;          //电话
    private BigDecimal enabled;          //是否启用
    private String nice_name;       //真是姓名
    private Date registerdate;      //注册时间
    private Date lastlogintime;     //最后登录时间
    private String pwdque;          //保密问题
    private String pwdans;          //保密问题答案
    private String status;          //是否删除
    
    private IRole iRole;            //角色权限


    public String getUser_uuid() {
        return user_uuid;
    }

    public void setUser_uuid(String user_uuid) {
        this.user_uuid = user_uuid;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

//    public String getEnabled() {
//        return enabled;
//    }


    public void setEnabled(BigDecimal enabled) {
        this.enabled = enabled;
    }

    public String getNice_name() {
        return nice_name;
    }

    public void setNice_name(String nice_name) {
        this.nice_name = nice_name;
    }

    public Date getRegisterdate() {
        return registerdate;
    }

    public void setRegisterdate(Date registerdate) {
        this.registerdate = registerdate;
    }

    public Date getLastlogintime() {
        return lastlogintime;
    }

    public void setLastlogintime(Date lastlogintime) {
        this.lastlogintime = lastlogintime;
    }

    public String getPwdque() {
        return pwdque;
    }

    public void setPwdque(String pwdque) {
        this.pwdque = pwdque;
    }

    public String getPwdans() {
        return pwdans;
    }

    public void setPwdans(String pwdans) {
        this.pwdans = pwdans;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public IUser(String user_uuid, String username, String password, IRole iRole) {
        this.user_uuid = user_uuid;
        this.username = username;
        this.password = password;
        this.iRole = iRole;
    }

    public IUser(String user_uuid, String username, String password, String email, String mobile, BigDecimal enabled, String nice_name, Date registerdate, Date lastlogintime, String pwdque, String pwdans, String status, IRole iRole) {
        this.user_uuid = user_uuid;
        this.username = username;
        this.password = password;
        this.email = email;
        this.mobile = mobile;
        this.enabled = enabled;
        this.nice_name = nice_name;
        this.registerdate = registerdate;
        this.lastlogintime = lastlogintime;
        this.pwdque = pwdque;
        this.pwdans = pwdans;
        this.status = status;
        this.iRole = iRole;
    }

    public IUser(String user_uuid, String username, String password, String email, String mobile, BigDecimal enabled, String nice_name, Date registerdate, Date lastlogintime, String pwdque, String pwdans, String status) {
        this.user_uuid = user_uuid;
        this.username = username;
        this.password = password;
        this.email = email;
        this.mobile = mobile;
        this.enabled = enabled;
        this.nice_name = nice_name;
        this.registerdate = registerdate;
        this.lastlogintime = lastlogintime;
        this.pwdque = pwdque;
        this.pwdans = pwdans;
        this.status = status;
    }

    public IRole getiRole() {
        return iRole;
    }

    public void setiRole(IRole iRole) {
        this.iRole = iRole;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(iRole == null){
            return null;
        }
        List<GrantedAuthority> auths = new ArrayList<>();
        IRole role = this.getiRole();
        auths.add(new SimpleGrantedAuthority(role.getRole_name()));

        return auths;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
